
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/layer.css">
    <link rel="stylesheet" type="text/css" href="css/swiper.min.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script src="js/layer.js"></script>
    <script src="js/swiper.min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
</head>
<body>
<div class="nav"></div>
<div class="record top125 clearfix">
	<div class="record-title">
		余额
	</div>
	<div class="record-money clearfix">
		<span>00.00</span>
		<a href="javascript:;">充值</a>
	</div>
	<div class="select_money">
		<div class="select_money_title">选择充值金额</div>
		<ul class="clearfix select_moneyul">
		</ul>
		<div class="select_money_title wxselect_money_title">选择充值方式</div>
		<div class="pay_type">
			<div class="wx-pay" payType='03'>
				<a href="javascript:;">
					<span><img src="images/wxpay@2x.png"></span>
					<span>微信</span>
				</a>
			</div>
			<div class="ali-pay" payType='02'>
				<a href="javascript:;">
					<span><img src="images/zfbpay@2x.png"></span>
					<span>支付宝</span>
				</a>
			</div>
		</div>
	</div>
	<div class="record-list">
		<div class="record-title">支付记录</div>
		<div class='no-record'>
			<img src="images/kong3@2x.png">
		</div>
		<ul>
		</ul>
	</div>
</div>
</body>
<div class="search-box searchide"></div>
<script type="text/javascript">
	$(function(){
		var url = window.location.href;
		var domain = window.location.host;
		function getMyDate(str){  
            var oDate = new Date(str),  
            oYear = oDate.getFullYear(),  
            oMonth = oDate.getMonth()+1,  
            oDay = oDate.getDate(),  
            oHour = oDate.getHours(),  
            oMin = oDate.getMinutes(),  
            oSen = oDate.getSeconds(),  
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间  
            return oTime;  
	    }; 
	        //补0操作
	    function getzf(num){  
			if(parseInt(num) < 10){  
			  num = '0'+num;  
			}  
			return num;  
	    }
		// 显示错误信息弹框
	    function layerMsg(msg){
	        layer.open({
	            content: msg,
	            style: 'background-color:rgba(0,0,0,1); color:#fff; border:none;',
	            time: 3
	        }); 
	    }
	    var id = $.cookie("id");
	    var token = $.cookie('token_access');
	    if(token != undefined){
	        $.ajax({
	            url: window.baseUrl+'api/user/info',
	            type: 'get',
	            beforeSend: function (XMLHttpRequest) {
					XMLHttpRequest.setRequestHeader("token", token);
	        	},
	            success: function (data) {
	              // 个人中心列表
	              	if(data.code == '200'){
	              		$(".record-money span").html(data.datas.customer.balance+'元');
		                $.ajax({
							url: window.baseUrl+'api/user/payHistory',
							type: 'get',
							beforeSend: function (XMLHttpRequest) {
								XMLHttpRequest.setRequestHeader("token", token);
			            	},
							success: function (data) {
							      // 支付记录
							      var paylist = '';
							      if(data.datas.result.length == 0){
							      	$(".no-record").show();
							      }else{
							      	for(var i = 0;i<data.datas.result.length;i++){
							      		var moviveName = data.datas.result[i].movieName;
							      		if(moviveName == undefined){
							      			moviveName = '充值';
							      		}
							          	paylist = paylist +'<li class="clearfix"><div class="pay-left">';
							          	paylist = paylist +'<div class="pay-name">'+moviveName+'</div>';
							          	paylist = paylist +'<div class="pay-time">'+getMyDate(data.datas.result[i].createTime)+'</div>';
							          	paylist = paylist +'</div><div class="pay-number">支付'+data.datas.result[i].money+'元</div></li>';
							          }
							        $(".record-list ul").html(paylist)
							    }
							      
							}
						});
	              	}else{
	              		window.location.href="login.html";
	              	}
	            }
	        });
	    }else{
	      window.location.href="login.html";
	    }
	    function getQueryString(name) {
	        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	        var r = window.location.search.substr(1).match(reg);
	        if (r != null) return (r[2]);
	        return null;
	    }
        var tag = getQueryString('tag');
	    $(".record-money a").on("click",function(){
	    	$(".select_money").toggle();
	    })
	    if(tag == 'ye'){
	    	$(".select_money").toggle();
	    }
	    $(".pay_type div").on("click",function(){
	    	// 支付
			var payType = $(this).attr('payType');
			var price = $(".selectMoneyActive").attr('data-id');
			$.ajax({
		        url:window.baseUrl+'api/order/createOrder',
		        type:'Post',
		        dataType:'json',
		        data:{
		            price:price,
		            payType:payType,
		            returnUrl:url,
					url:domain
		        },
		        beforeSend: function (XMLHttpRequest) {
	         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
	            },
		        success:function(data){ 
		            var code = data.code;
		            if(code === '200'){
	                	var istype = data.datas.istype;
		                var notify_url = data.datas.notify_url;
		                var orderid = data.datas.orderid;
		                var price = data.datas.price;
		                var return_url = data.datas.return_url;
		                var key = data.datas.key;
		                uid = data.datas.uid;
		                // 用表单post的方式，post参数并跳转到此网址，显示我们的支付页。
		                function postForm(URL, PARAMS){ 
						    var temp = document.createElement("form");        
						    temp.action = URL;        
						    temp.method = "post";
						    temp.style.display = "none";  
						    for (var x in PARAMS) {        
						        var opt = document.createElement("textarea");        
						        opt.name = x; 
						        opt.value = PARAMS[x];      
						        temp.appendChild(opt);        
						    }        
						    document.body.appendChild(temp);        
						    temp.submit();        
						    return temp;        
						  }
						postForm('https://pay.bbbapi.com/', {
				            istype : istype,
				            notify_url : notify_url,
				            orderid : orderid,
				            price : price,
				            return_url: return_url,
				            key: key,
				            uid:uid
					    })
		            }else{
		            	layerMsg(data.message);
		            }
		        }
		    })
	    })
	    // 充值金额
	    $.ajax({
			url: window.baseUrl+'api/dictionary/getRechargeList',
			type: 'get',
			success: function (data) {
			  	var paylistStr = '';
			  	for(var i = 0;i<data.datas.length;i++){
			  		if(i == 0){
			  			paylistStr = paylistStr +'<li data-id="'+data.datas[i].caption+'" class="selectMoneyActive">'+data.datas[i].caption+'</li>';
			  		}else{
			  			paylistStr = paylistStr +'<li data-id="'+data.datas[i].caption+'">'+data.datas[i].caption+'</li>';
			  		}
					
				}
				$(".select_moneyul").html(paylistStr)
				$(".select_money .select_moneyul li").on("click",function(){
			    	$(".select_money ul li").removeClass("selectMoneyActive");
			    	$(this).addClass("selectMoneyActive");
			    })
			}
		});
    })
</script>
</html>